<template>
  <div class="login">
    <el-form
      :rules="rules"
      ref="ruleLoginForm"
      class="login-container"
      label-position="left"
      :model="loginForm"
      label-width="0px"
      v-loading="loading"
    >
      <h3 class="login_title">系统登录</h3>
      <el-form-item prop="username">
        <el-input
          type="text"
          v-model="loginForm.username"
          auto-complete="off"
          placeholder="账号"
        ></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          type="password"
          v-model="loginForm.password"
          auto-complete="off"
          placeholder="密码"
        ></el-input>
      </el-form-item>
      <el-form-item style="width: 100%">
        <el-button
          type="primary"
          @click="Into()"
          style="width: 100%"
          >登录</el-button
        >
        <div style="text-align: center">
          <a @click="toRegister()">快速注册</a>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { Tologin } from "@/apis/getData.js";
export default {
  name: "Login",
  data() {
    return {
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "change" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      checked: true,
      loginForm: {
        username: "",
        password: "",
      },
      loading: false,
    };
  },

  methods: {
    Into(){
      let params=new FormData();
      params.append("username",this.loginForm.username)
      params.append("password",this.loginForm.password)
      Tologin(params).then((res)=>{
        console.log(res.data)
        if(res.data.message==1){
          let userdate=res.data.data;
          userdate.datetime=new Date().getTime();
          this.$store.commit("updateUser",userdate);
          alert("登录成功！")
          this.$router.go(0)
        }else if(res.data.message==0){
          alert("账号或密码错误")
        }else{
          alert("登录失败")
        }
      })
    },
    toRegister(){
      this.$router.push('/register');
    }
  },
};
</script>

<style scoped>
.login-container {
  border-radius: 15px;
  background-clip: padding-box;
  margin: 180px auto;
  width: 350px;
  padding: 35px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}

.login_title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
}

.login_remember {
  margin: 0px 0px 35px 0px;
  text-align: left;
}
.login a{
  text-decoration: none;
}

.login a:hover{
  color: cornflowerblue;
}
</style>